def yanghui_triangle(n):
    """
    杨辉三角
    :param n:
    :return:
    """
    result = []
    if n <= 0:
        return result
    if n == 1:
        result.append([1])
    if n == 2:
        return [[1], [1, 1]]
    result = [[1], [1, 1]]
    for i in range(2, n):
        result.append([1])
        for j in range(1, i):
            result[i].append(result[i - 1][j - 1] + result[i - 1][j])
        result[i].append(1)
    return result


result = yanghui_triangle(10)
print(result)
hh = len(result)
for i in range(hh):
    ll = len(result[i])
    print(" " * (hh - ll), end="")
    for j in range(ll):
        print(result[i][j], end=" ")
    print()

